<template>
  <lc-chart-funnel
    ref="funnelRef"
    :options="funnelOptions"
    :map-options="funnelMapOptions"
    :data="funnelData"
    style="--height: 300px"
  ></lc-chart-funnel>
</template>

<script setup>
import { ref } from "vue";

import { request } from "@/apis/request";
defineOptions({
  name: "Funnel",
});

const funnelRef = ref(null);
const funnelData = ref([]);
const funnelMapOptions = ref({});
const funnelOptions = ref({
  title: { text: "", top: 10, left: 10 },
  legend: { right: 10, top: 10 },
  tooltip: { trigger: "item", formatter: "" },
  grid: {
    left: "6%",
    top: "20%",
    right: "5%",
    bottom: "10%",
    containLabel: true,
  },
  color: [
    "rgba(62, 115, 241, 1)",
    "rgba(72, 192, 179, 1)",
    "rgba(123, 185, 44, 1)",
    "rgba(254, 216, 49, 1)",
    "rgba(243, 113, 50, 1)",
    "rgba(240, 54, 62, 1)",
    "rgba(250, 97, 102, 1)",
    "rgba(151, 96, 226, 1)",
  ],
  series: [
    {
      name: "漏斗图",
      type: "funnel",
      gap: 2,
      label: { show: true, position: "inside" },
      labelLine: { length: 10, lineStyle: { width: 1, type: "solid" } },
      itemStyle: { borderColor: "#fff", borderWidth: 1 },
      emphasis: { label: { fontSize: 20 } },
    },
  ],
});

const getFunnelData = async () => {
  try {
    let params = { url: "", method: "get", params: {} };
    const res = await request(params);
    if (res) {
      funnelData.value = res.data || [];
    }
  } catch (e) {
    console.error("获取数据出错: " + e);
  }
};
getFunnelData();
</script>
